#pragma once
#include "p2.h"
#include "OrderInfo.h"
#include <string>
#include <vector>
#include <map>
using namespace std;

class COrderManager;
class CMainOrderPanel;

class CAccountInfo
{
public:
	CAccountInfo();
	~CAccountInfo();

	CString Code;
	CString HipenCode;
	CString Desc;

	double DepositTotal;
	double DepositCash;
	double MarginTotal;
	double MarginCash;
	double LiquidTotal;
	double LiquidCash;
	double Commission;
	double DailyPL;
	double EvalPL;
	double MaxOrderQty;
	double AccPL;
	COrderManager* OrderMgr() const { return m_pOrderMgr; }
	void OrderMgr(COrderManager* val) { m_pOrderMgr = val; }

	CMainOrderPanel* MainWnd() const { return m_pMainWnd; }
	void MainWnd(CMainOrderPanel* val) { m_pMainWnd = val; }

	mapOrder m_OrderMap;
	mapOrderByPrice m_SellMap;
	mapOrderByPrice m_BuyMap;

	COrderInfo* AddOrder(long a_AcptNm);
	COrderInfo* FindOrder(long a_AcptNm);
	COrderInfo* FindPendingOrder(double a_Price, IPositionType a_PositionType, IOrderStateType a_OrderState);
	OrderVector* AddBuySellMap(COrderInfo* a_Order);
	//OrderVector* AddBuySellMap(COrderInfo* a_Order);
	void MoveOrder(IPositionType a_PosiType, double a_PreVal, double a_NewVal);
	void MoveOrderOnBuySellMap(COrderInfo* a_PreOrder, COrderInfo* a_NewOrder);
	OrderVector* AddToMap(IPositionType a_PosiType, double a_Price);
	OrderVector* FindFromBuySellMap(IPositionType a_PosiType, double a_Price);

	void UpdateOrderOnBuySellMap(COrderInfo* a_CurOrder);

	int GetUnfilledOrderSum(OrderVector* a_OrderVector);
	int GetBuyOrderSum();
	int GetSellOrderSum();
	void RemoveFilledOrder(COrderInfo* a_Order);
	void RemoveChangedOrder(COrderInfo* a_Order);

	void ClearBuySellMap();
private:
	COrderManager* m_pOrderMgr;
	CMainOrderPanel* m_pMainWnd;
};

typedef vector<CAccountInfo*> vectorAccount;
typedef map<wstring, CAccountInfo*> mapAccount;
typedef pair<wstring, CAccountInfo*> pairAccountInfo;
typedef map< wstring, CAccountInfo* >::iterator AccountInfoPos;

